package br.com.lh.urabuilder.view
{
	
	import br.com.lh.urabuilder.domain.xml.UraXml;
	import br.com.lh.urabuilder.event.SaveUraEvent;
	import br.com.lh.urabuilder.model.UraModelLocator;
	import br.com.lh.urabuilder.view.base.APopUpConfirmationBarContainer;
	
	import com.adobe.cairngorm.control.CairngormEvent;
	
	import mx.collections.ArrayCollection;
	import mx.containers.Form;
	import mx.containers.FormItem;
	import mx.controls.TextInput;
	
	public class SaveForm extends APopUpConfirmationBarContainer{
	
		private var componentCanvasChildren:ArrayCollection;
		private var modelLocator:UraModelLocator;
		private var formItem:FormItem = new FormItem();
		private var input:TextInput = new TextInput();
		private var alias:String;
		
		public function SaveForm(modelLocator:UraModelLocator){
			this.modelLocator = modelLocator;
			this.title = "Save";
			createFields(createForm());
			createButtons();
			this.setFocus();
		}

		private function createFields(form:Form):void{
			formItem.label = "Alias";
			formItem.addChild(input);
			form.addChild(formItem);
		}

		private function createForm():Form{
			var form:Form = new Form();
			addChild(form);
			return form;
		}

		public override function okEvent():CairngormEvent{
			var uraXml:UraXml = modelLocator.xmlManager.getUraXml();
			uraXml.xmlString = uraXml.xml.toString();
			uraXml.alias = input.text;
			return new SaveUraEvent(uraXml.alias);
		}



	}
}